﻿using CKS.PLC.Core.CronJob;
using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.Dto.Business.ProductionControl;
using ZR.Model.Models.ProductionControl;
using ZR.Service.IService.ProductionControl;

//创建时间：2025-02-28
namespace ZR.Admin.WebApi.Controllers
{
    /// <summary>
    /// OP80钎焊记录
    /// </summary>
    [Verify]
    [Route("business/DcOp80Record")]
    [ApiExplorerSettings(GroupName = "business")]
    public class DcOp80RecordController : BaseController
    {
        /// <summary>
        /// OP80钎焊记录接口
        /// </summary>
        private readonly IDcOp80RecordService _DcOp80RecordService;

        public DcOp80RecordController(IDcOp80RecordService DcOp80RecordService)
        {
            _DcOp80RecordService = DcOp80RecordService;
        }

        /// <summary>
        /// 查询OP80钎焊记录列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "dcop80record:list")]
        public IActionResult QueryDcOp80Record([FromQuery] DcOp80RecordQueryDto parm)
        {
            var response = _DcOp80RecordService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询OP80钎焊记录详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "dcop80record:query")]
        public IActionResult GetDcOp80Record(long Id)
        {
            var response = _DcOp80RecordService.GetInfo(Id);

            var info = response.Adapt<DcOp80RecordDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加OP80钎焊记录
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "dcop80record:add")]
        [Log(Title = "OP80钎焊记录", BusinessType = BusinessType.INSERT)]
        public IActionResult AddDcOp80Record([FromBody] DcOp80RecordDto parm)
        {
            var modal = parm.Adapt<DcOp80Record>().ToCreate(HttpContext);

            var response = _DcOp80RecordService.AddDcOp80Record(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新OP80钎焊记录
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "dcop80record:edit")]
        [Log(Title = "OP80钎焊记录", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateDcOp80Record([FromBody] DcOp80RecordDto parm)
        {
            var modal = parm.Adapt<DcOp80Record>().ToUpdate(HttpContext);
            var response = _DcOp80RecordService.UpdateDcOp80Record(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除OP80钎焊记录
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete/{ids}")]
        [ActionPermissionFilter(Permission = "dcop80record:delete")]
        [Log(Title = "OP80钎焊记录", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteDcOp80Record([FromRoute] string ids)
        {
            var idArr = Tools.SplitAndConvert<long>(ids);

            return ToResponse(_DcOp80RecordService.Delete(idArr));
        }

        /// <summary>
        /// 获取料架单元格的数据
        /// </summary>
        /// <returns></returns>
        [HttpPost("GetShelfData")]
        public IActionResult GetShelfData()
        {
            var job = InternalApp.JobProvider.GetService<CacheDataJob>();

            var response = new {
                DataL =job.GetData(1),
                DataR =job.GetData(2),
            
            };
            return SUCCESS(response);
        }

    }
}